const zmfDbClient = uniCloud.importObject("zmf-db-client");
const types = {
	clear : "clear",
	getList : "getList"
}
export default {
	namespaced: true,
	state: {
		list:[],
		hasNext: true
	},
	getters: {
		
	},
	mutations: {
		[types.clear] (state){
			state.list = []
			state.hasNext = true
		},
		async [types.getList] (state, {uid,start,page}){
			if(state.hasNext === false){
				return
			}
			const param = {
				user_id: uid,
				start_num:start,
				page_num:page
			}
			const resp = await zmfDbClient.getUniIdScoresByPage(param);
			const {errCode,userRecord} = resp
			if(userRecord !== undefined && userRecord.length > 0){
				const temp = state.list
				state.list = temp.concat(userRecord);
			}
			
			if(userRecord !== undefined && userRecord.length < page){
				state.hasNext = false
			}
			
		}
	},
	actions: { 
		async clear({commit}){
			commit(types.clear)
		},
		async getList({commit},{uid,start,page}){
			if(uid === undefined || start === undefined || page === undefined){
				console.error("参数错误");
				return
			}
			commit(types.getList, {uid,start,page})
		}
	}
}
